//
//  NearViewController.m
//  hai游～
//
//  Created by jakf_17 on 15/5/26.
//  Copyright (c) 2015年 jakf_17. All rights reserved.
//

#import "NearViewController.h"
#import <AFNetworking/AFNetworking.h>
#import "NearTableViewCell.h"
#import "LocationManager.h"
@interface NearViewController ()<UITableViewDataSource, UITableViewDelegate, GetLocationDelegate>

@end

@implementation NearViewController


- (void)dealloc
{
    [_tableView release];
    [_array release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self createMytableView];
    LocationManager *manager = [[LocationManager alloc] init];
    manager.delegate = self;
    [manager createMylocation];
}

- (void)createMytableView
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, [[UIScreen mainScreen] bounds].size.width, self.view.frame.size.height - 64 - 20) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    [_tableView release];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _array.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellPool = @"cellPool";
    NearTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellPool];
    if (cell == nil) {
        cell = [[[NearTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellPool] autorelease];
    }
    return cell;
}

- (void)getLocation:(CLLocationCoordinate2D)coordinate
{
    double latitude = coordinate.latitude;
    double longitude = coordinate.longitude;
    [self loadDataSourceWithLatitude:latitude longitude:longitude];
}
- (void)loadDataSourceWithLatitude:(double)latitude longitude:(double)longitude
{
    NSString *webSite = [NSString stringWithFormat:@"http://api.breadtrip.com/place/pois/nearby/?category=0&start=0&count=20&latitude=%f&longitude=%f",latitude, longitude];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:webSite parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"ok");
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}
@end
